$(document).ready(function()
{
    init_menu();
//    $("form").validate();
});

function init_menu() {
   var showSubMenu = false;
   var sfAdminMenuHover = false;
   var _lastSelected = null;
   $("#sf_admin_menu ul.menu li.menu_level_0")
   .click( function(){
      $(this).children("ul.menu_level_1").show();
      $(this).addClass("selected");
      showSubMenu = true;
   })
   .mouseenter( function()
   {
        if(_lastSelected){
            hideSubMenu(_lastSelected);
        }

        if(showSubMenu){
            $(this).children("ul.menu_level_1").show();
            $(this).addClass("selected");
        }
        _lastSelected = $(this);
   });

   $("#sf_admin_menu").hover( function()
   {
       sfAdminMenuHover = true;
   },
   function()
   {
       sfAdminMenuHover = false;
   });

  $("body").click( function(){
      if(!sfAdminMenuHover){
          showSubMenu = false;
          hideSubMenu($("#sf_admin_menu ul.menu li.menu_level_0"));
      }
  });
}

function hideSubMenu(_this){
    _this.children( "ul.menu_level_1" ).hide();
    _this.removeClass("selected");
}